//
//  CacheTool.m
//  CreditHub
//
//  Created by xinhualong on 2024/9/14.
//

#import "CacheTool.h"

@implementation CacheTool
+ (instancetype)sharedInstance {
    static CacheTool *instance = nil;
    static dispatch_once_t once = 0;
    dispatch_once(&once, ^{
        instance = [[CacheTool alloc] init];
    });
    return instance;
}

- (void)updateUsetInfo:(NSDictionary *)dic{
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject:dic forKey:UserInfoKey];
    [defaults synchronize];
}
- (UserInfoModel *)getUserInfo{
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSDictionary *dicUserInfo = [defaults objectForKey:UserInfoKey];
    UserInfoModel *userInfo = [[UserInfoModel alloc] init];
    if( [dicUserInfo isKindOfClass: [NSDictionary class]] ){
        userInfo.cuddle = CHStringIsEmpty([dicUserInfo objectForKey:@"cuddle"])?@"":[dicUserInfo objectForKey:@"cuddle"];
        userInfo.sleep = CHStringIsEmpty([dicUserInfo objectForKey:@"sleep"])?@"":[dicUserInfo objectForKey:@"sleep"];
        userInfo.areal = CHStringIsEmpty([dicUserInfo objectForKey:@"cuddle"])?@"":[dicUserInfo objectForKey:@"areal"];
        
    }else{
        userInfo.cuddle = @"";
        userInfo.sleep = @"";
        userInfo.areal = @"";
    }
    return userInfo;
}

- (void)updateCityList:(NSArray *)dic{
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject:dic forKey:CityKey];
    [defaults synchronize];
}
- (void)getCityList{
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSArray *cityList = [defaults objectForKey:CityKey];
    if( [cityList isKindOfClass: [NSArray class]] ){
        
    }
}

@end
